<?php 
namespace Home\Controller;
use Think\Controller;

class PermissionController extends Controller
{
	public function index(){return;}

	public function all()
	{
		if(IS_POST){
			$page = I("post.page",1);
			$rows = I("post.rows",10);
			$res = D("Permission")->get_all($page,$rows,$type);
			// $output['result'] = $this->getState("");
			$output['total'] = $res['total'];
			$output['rows'] = $res['res'];
			echo json_encode($output);
		}else{
			// dump("111");exit();
			// $output['result'] = $this->getState("5");
			// echo json_encode($output);
		}
	}

	public function add()
	{
		if(IS_POST){
			$permission_name = I("post.permission_name","");
			$type = I("post.type","");
			$url = I("post.url","");
			$status = I("post.status","");
			// $parent_id = I("post.parent_id","");
			if(($permission_name && $url && $status) != ''){
				$res = D("Permission")->add_per($permission_name,$type,$url,$status,$parent_id);
			}
			$res?$output = 1:$output = 0;
			echo json_encode($output);
		}else{
			// $output['result'] = $this->getState("5");
			// echo json_encode($output);
		}
	}

	public function delete()
	{
		if(IS_POST){
			$id = I("post.id","");
			$res = D("Permission")->delete_per($id);
			$res?$output = 1:$output = 0;
			echo json_encode($output);
		}else{
			// $output['result'] = $this->getState("5");
			// echo json_encode($output);
		}
	}

	public function edit_select()
	{
		if(IS_POST){
			$id = I("post.id","");
			$res = D("Permission")->select_per($id);
			$res?$output = $res:$output = [];
			echo json_encode($output);
		}else{
			$id = I("post.id","1");
			$res = D("Permission")->select_per($id);
			$res?$output = $res:$output = [];
			echo json_encode($output);
			// $output['result'] = $this->getState("5");
			// echo json_encode($output);
		}
	}

	public function edit()
	{
		if(IS_POST){
			$id = I("post.id","");
			$permission_name = I("post.permission_name","");
			$type = I("post.type","");
			$url = I("post.url","");
			$status = I("post.status","");
			$parent_id = I("post.parent_id","");
			$res = D("Permission")->edit_per($id,$permission_name,$type,$url,$status,$parent_id);
			$res?$output= 1:$output = 0;
			echo json_encode($output);
		}else{
			// $output['result'] = $this->getState("5");
			// echo json_encode($output);
		}
	}
}